package com.right.handler;

import com.right.command.CsCommand;
import com.right.util.StringUtil;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * <pre>
 *     @author : pillar
 *     e-mail : 347637454@qq.com
 *     time   : 2019/1/2 15:59
 *     desc   :
 *     version: 1.0
 * </pre>
 */
@Slf4j
public class ControlHandler implements PackageHandler {
    private CountDownLatch lock;
    private List<String> dataList;
    private String currentCmd;

    @Override
    public boolean applies(List<String> dataList) {
        return null!=currentCmd && currentCmd.equals(dataList.get(0));
    }

    @Override
    public boolean handleMessage(ChannelHandlerContext ctx, List<String> dataList) {
        log.info("收到消息，释放锁");
        this.dataList = dataList;
        this.lock.countDown();
        return false;
    }

    public void setLock(CountDownLatch lock) {
        this.lock = lock;
    }

    public List<String> getDataList() {
        return dataList;
    }

    public void setDataList(List<String> dataList) {
        this.dataList = dataList;
    }

    public void setCurrentCmd(String currentCmd) {
        this.currentCmd = currentCmd;
    }

    public String getCurrentCmd() {
        return currentCmd;
    }
}
